package com.scott.ch24.student.controller;

import com.scott.ch24.student.bean.StudentBean;
import com.scott.ch24.student.service.StudentService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Qualifier;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.HashMap;
import java.util.Map;

/**
 * @author 黄后林
 * @version 1.0
 * @date 2021-11-25 10:35:57
 */

@RestController
@RequestMapping("student")
public class StudentController {

    @Autowired
    //@Qualifier("studentServiceImpl")
    private StudentService service;

    /**
     * 方法描述: http://localhost:8080/student/add post
     * @author: 黄后林
     * @date: 2021/11/25 10:41
     * @param student
     * @return java.util.Map<java.lang.String
     * @return java.lang.Object>
     */
    @RequestMapping("add")
    public Map<String,Object> add(@RequestBody StudentBean student){

        Map<String,Object> map = new HashMap<>();

        try {
            service.addStudent(student);
            map.put("code",200);
            map.put("message","success");
        }catch (Exception exception){
            map.put("code",500);
            map.put("message",exception);
        }
        return map;
    }

}
